package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/url"

	"github.com/gorilla/websocket"
)

func main() {
	u := url.URL{Scheme: "ws", Host: "localhost:8080", Path: "/mcp"}
	conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
	if err != nil {
		log.Fatal("Dial failed:", err)
	}
	defer conn.Close()

	request := map[string]interface{}{
		"action":      "get_resource",
		"resource_id": 2,
	}
	if err := conn.WriteJSON(request); err != nil {
		log.Fatal("Write failed:", err)
	}

	_, message, err := conn.ReadMessage()
	if err != nil {
		log.Fatal("Read failed:", err)
	}

	var response map[string]interface{}
	if err := json.Unmarshal(message, &response); err != nil {
		log.Fatal("Parse failed:", err)
	}

	fmt.Printf("Received: %v\n", response)
}
